package com.showcal.service.listener;

import com.showcal.platform.biz.IntegralDetailManager;
import com.showcal.platform.domain.IntegralRuleTypeEnum;
import com.showcal.platform.request.IntegralDetailCreateRequest;
import com.showcal.service.event.IMMessageSendEvent;
import com.showcal.service.event.bean.IMMessagBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 发送消息增加积分
 * Created by guzhixiong on 2015/11/17.
 */
@Component
public class IntegralAddForQuestionListener  implements ApplicationListener<IMMessageSendEvent> {
    @Autowired
    private IntegralDetailManager integralDetailManager;
    @Async
    @Override
    public void onApplicationEvent(IMMessageSendEvent imMessageSendEvent) {
        System.out.println("增加积分................");
        IntegralDetailCreateRequest integralDetailCreateRequest = new IntegralDetailCreateRequest();
        integralDetailCreateRequest.setType(IntegralRuleTypeEnum.QUESTION.name());
        IMMessagBean messagBean = (IMMessagBean) imMessageSendEvent.getSource();
        integralDetailManager.create(integralDetailCreateRequest, messagBean.getPassport());
    }
}
